home *** CD-ROM | disk | FTP | other *** search
/ Nothing but Tetris / Nothing but Tetris.iso / menu.lha / IBMPC / MIXED2 / C_TETRIS / T_TRIS.C next >
Text File  |  1980-01-06  |  30KB  |  995 lines

  1. /* T_TRIS version 2.01 adapted by Eric Lapaille
  2.                             Quai du Condroz 17
  3.                             B - 4020 LIEGE
  4.                             BELGIUM
  5.    English translation.
  6.    Modified for Turbo C 2.0.
  7.    Cursor and mouse hiding.
  8.    Please, leave this header unmodified
  9.  
  10.    I don't know if the original TETRIS is a commercial product, a public
  11.    domain or anyone else. So, if this T_TRIS violates any copyright law
  12.    or causes prejudice to some people, please let me know and I'll
  13.    immediately remove T_TRIS from the PD market.
  14.  
  15.    If you like this product and use it often, respect the shareware concept
  16.    and send to one of us a disk full of great public domain software.
  17.  
  18.    Sorry for spelling errors, but my native tongue is FRENCH. */
  19.  
  20.  
  21.  
  22. /* ---------------------------------------------------------------------- */
  23. /* T_TRIS                                                                 */
  24. /* Taak       Leuk spelen met de gebruiker                                */
  25. /*                                                                        */
  26. /* Compiler   MicroSoft C 5.0    Large Model                              */
  27. /*            Quick     C 1.0     ,,    ,,                                */
  28. /*                                                                        */
  29. /* (c) 1988   R.A. van Wier                                               */
  30. /*            Nwe Prinsengr. 60 II                                        */
  31. /*            1018 VT  Amsterdam                                          */
  32. /*                                                                        */
  33. /*            Dit programma is een "kloon" van het tetris programma       */
  34. /*            van A. Pajitnov & V. Gerasimov.                             */
  35. /*                                                                        */
  36. /*            Deze software mag door iedereen gebruikt, gecopieerd,       */
  37. /*            aangepast en verspreid worden onder voorwaarde dat altijd   */
  38. /*            de juiste source wordt meegeleverd en dat de CopyRight      */
  39. /*            teksten niet worden verwijderd.                             */
  40. /*                                                                        */
  41. /*            Houdt FreeWare VIRUS vrij, lever de SOURCE mee !            */
  42. /*                                                                        */
  43. /* ---------------------------------------------------------------------- */
  44.  
  45. #include <bios.h>
  46. #include <conio.h>
  47. #include <dos.h>
  48. #include <stdio.h>
  49. #include <stdlib.h>
  50.  
  51. static int     REACTION_TIME,
  52.             start_level,
  53.             level;
  54. static char    name[255];
  55.  
  56. #define MDA_SEG 0xB000
  57. #define CGA_SEG 0xB800
  58.  
  59. #define KEY_END     0x011B
  60. #define KEY_RIGHT   0x4D00
  61. #define KEY_LEFT    0x4B00
  62. #define KEY_PAUSE   0x4800
  63. #define KEY_DROP    0x5000
  64. #define KEY_ROTATE  0x1C0D
  65.  
  66. #define MOUSE_STEP   16
  67.  
  68. #define SCREEN_BLANKING      0x0700 | ' '
  69.  
  70. #define CHAR_FULL           (unsigned char)219
  71. #define COLOR_BLACK        0
  72. #define COLOR_BROWN        6
  73. #define COLOR_GREY         7
  74. #define COLOR_GREEN       10
  75. #define COLOR_BLUE        11
  76. #define COLOR_RED         12
  77. #define COLOR_VIOLET      13
  78. #define COLOR_YELLOW      14
  79. #define COLOR_WHITE       15
  80. #define COLOR_SCORE       75
  81. #define COLOR_TOPSCORE    30
  82. #define COLOR_LOGO        31
  83.  
  84. #define COLOR_RAND         3
  85.  
  86. #define LOG_SIZE_REG       20
  87. #define LOG_SIZE_COL       10
  88.  
  89. #define MIN_REG            2
  90. #define MAX_REG            (LOG_SIZE_REG + MIN_REG)
  91. #define MIN_COL            28
  92. #define MAX_COL            (MIN_COL + (LOG_SIZE_COL * 2))
  93.  
  94. #define NUMBER_FORMS      7
  95. #define FORM_SIZE          3
  96.  
  97. #define SCORE_FILE      "T_TRIS.TOP"
  98. #define NUMBER_SCORE       20
  99.  
  100. typedef int     FORM[FORM_SIZE][FORM_SIZE];
  101.  
  102. static FORM            forms[NUMBER_FORMS];
  103.  
  104. static FORM            huidige_form;
  105.  
  106. static int             form_point[NUMBER_FORMS];
  107.  
  108. static int            log_screen[LOG_SIZE_REG][LOG_SIZE_COL];
  109.  
  110. static unsigned far  *ptr_screen;
  111.  
  112. static int            col;
  113.  
  114. static long           points;
  115. static unsigned       key;
  116. static int            mouse_present = -1, mouse_col;
  117.  
  118. /* ----------- position the cursor ------------- */
  119.  
  120. void cursor(int x, int y)
  121. {
  122.    union REGS  rg;
  123.     rg.x.ax = 0x0200;
  124.     rg.x.bx = 0;
  125.     rg.x.dx = ((y << 8) & 0xff00) + x;
  126.     int86(16, &rg, &rg);
  127. }
  128.  
  129.  
  130. /* ---------------------------------------------------------------------- */
  131. /* CHECK_MOUSE                                                            */
  132. /* Test if mouse is present                                               */
  133. /*                                                                        */
  134. /* ---------------------------------------------------------------------- */
  135. static void check_mouse()
  136. {
  137.    union REGS  regs;
  138.  
  139.    regs.x.ax = 0;
  140.    int86(0x33,®s,®s);
  141.  
  142.    if ( regs.x.ax == 0 )
  143.       mouse_present = 0;
  144.    else
  145.       mouse_present = 1;
  146.  
  147.    if ( mouse_present )
  148.      {
  149.       regs.x.ax = 3;
  150.       int86(0x33,®s,®s);
  151.       mouse_col = regs.x.cx;
  152.       regs.x.ax = 7;
  153.       regs.x.cx = MIN_COL * 8;
  154.       regs.x.dx = (MAX_COL-1) * 8;
  155.       int86(0x33,®s,®s);
  156.      }
  157. }
  158.  
  159. /* ---------------------------------------------------------------------- */
  160. /* MOUSE_CLICK                                                            */
  161. /* Check for mouse click                                                  */
  162. /*                                                                        */
  163. /* ---------------------------------------------------------------------- */
  164. static int mouse_click()
  165. {
  166.    int         retcode;
  167.    union REGS  regs;
  168.    static    unsigned    vclick = 0;
  169.  
  170.    regs.x.ax = 3;
  171.    int86(0x33,®s,®s);
  172.  
  173.    if (  ( regs.x.bx != 0 ) && ( regs.x.bx != vclick ) )
  174.       retcode = 1;
  175.    else
  176.       retcode = 0;
  177.  
  178.    vclick = regs.x.bx;
  179.    return(retcode);
  180. }
  181. /* ---------------------------------------------------------------------- */
  182. /* READ_MOUSE                                                             */
  183. /* Read mouse move                                                        */
  184. /*                                                                        */
  185. /* ---------------------------------------------------------------------- */
  186. static int read_mouse()
  187. {
  188.    int         retcode;
  189.    union REGS  regs;
  190.  
  191.    retcode = 0;
  192.  
  193.    if ( mouse_present < 0 )
  194.       check_mouse();
  195.  
  196.    if ( mouse_present )
  197.      {
  198.       if ( mouse_click() )
  199.         {
  200.          key = KEY_ROTATE;
  201.          retcode = 1;
  202.         }
  203.       else
  204.         {
  205.          regs.x.ax = 3;
  206.          int86(0x33,®s,®s);
  207.          if ( (mouse_col - (int)regs.x.cx) >= MOUSE_STEP )
  208.           {
  209.             key = KEY_LEFT;
  210.           mouse_col -=  MOUSE_STEP;
  211.             retcode = 1;
  212.           }
  213.          else
  214.           {
  215.             if ( ( (int)regs.x.cx - mouse_col) >= MOUSE_STEP )
  216.             {
  217.                key = KEY_RIGHT;
  218.             mouse_col +=  MOUSE_STEP;
  219.                retcode = 1;
  220.             }
  221.             else
  222.             {
  223.                regs.x.ax = 11;
  224.                int86(0x33,®s,®s);
  225.                if ( (int)regs.x.dx >= MOUSE_STEP )
  226.                {
  227.                   key = KEY_DROP;
  228.                   retcode = 1;
  229.                }
  230.           }
  231.          }
  232.       }
  233.    }
  234.  
  235.    return(retcode);
  236. }
  237. /* ---------------------------------------------------------------------- */
  238. /* ACTION                                                                 */
  239. /* Check for reaction time                                                */
  240. /*                                                                        */
  241. /* ---------------------------------------------------------------------- */
  242. static int action()
  243. {
  244.    int         retcode;
  245.    static   long        last = 0,
  246.                delay;
  247.    #if Microsoft
  248.     _bios_timeofday(_TIME_GETCLOCK,&delay);
  249.    #else
  250.     delay=biostime(0,delay);
  251.    #endif
  252.    if ( ( delay - last ) >= REACTION_TIME )
  253.      {
  254.       retcode = 1;
  255.       last   = delay;
  256.      }
  257.    else
  258.       retcode = 0;
  259.  
  260.    return(retcode);
  261. }
  262.  
  263. /* ---------------------------------------------------------------------- */
  264. /* READ_KEY                                                               */
  265. /* Check and read key hitting                                             */
  266. /*                                                                        */
  267. /* ---------------------------------------------------------------------- */
  268. static int read_key()
  269. {
  270.    int         retcode;
  271.  
  272.    if ( bioskey(1) )
  273.      {
  274.      key = bioskey(0);
  275.       retcode = 1;
  276.      }
  277.    else
  278.       retcode = read_mouse();
  279.  
  280.    return(retcode);
  281. }
  282.  
  283. static void wait_key()
  284.    {
  285.    while(   ( !read_key() ) &&  ( !read_mouse()  )  );
  286.    }
  287.  
  288. static void flush_key_buffer()
  289. {
  290.    while (  ( read_key() ) || ( read_mouse() ) );
  291. }
  292.  
  293. /* ---------------------------------------------------------------------- */
  294. /* BEEP                                                                   */
  295. /* Performs beep                                                          */
  296. /*                                                                        */
  297. /* ---------------------------------------------------------------------- */
  298. static void beep()
  299. {
  300.    putch('\x07');
  301. }
  302.  
  303. /* ---------------------------------------------------------------------- */
  304. /* SHOW_DRAWING                                                           */
  305. /* Show the right form in the right color                                 */
  306. /*                                                                        */
  307. /* ---------------------------------------------------------------------- */
  308. static void show_drawing(line,column,color,drawing)
  309. int            line,
  310.                column,
  311.                color;
  312. unsigned
  313. char           drawing;
  314. {
  315.    int         i;
  316.  
  317.    i = (line * 80) + column;
  318.    ptr_screen[i] = (color << 8) | drawing;
  319. }
  320. /* ---------------------------------------------------------------------- */
  321. /* SHOW_STRING                                                            */
  322. /* Show the right string at the right place in the right color            */
  323. /*                                                                        */
  324. /* ---------------------------------------------------------------------- */
  325. static void show_string(line,column,color,string)
  326. int            line,
  327.                column,
  328.                color;
  329. unsigned
  330. char           string[];
  331. {
  332.    int         i;
  333.  
  334.    for ( i = 0; string[i]; i++ )
  335.       show_drawing(line,column+i,color,string[i]);
  336. }
  337.  
  338. /* ---------------------------------------------------------------------- */
  339. /* CLS                                                                    */
  340. /*                                                                        */
  341. /* ---------------------------------------------------------------------- */
  342. static void cls()
  343. {
  344.    int         i;
  345.  
  346.    for ( i = 0; i < 2000; i++) ptr_screen[i] = SCREEN_BLANKING;
  347. }
  348.  
  349. /* ---------------------------------------------------------------------- */
  350. /* INIT_SCREEN                                                            */
  351. /* Layout of the screen                                                   */
  352. /*                                                                        */
  353. /* ---------------------------------------------------------------------- */
  354.  
  355. static void init_screen()
  356. {
  357.    int         i;
  358.    union REGS  regs;
  359.    char        mystring[100];
  360.    long        delay;
  361.  
  362.    /* Timer and screen initialization  */
  363.  
  364.    regs.h.ah = 0x0F;
  365.    int86(0x10,®s,®s);
  366.  
  367.    #if Microsoft
  368.     _bios_timeofday(_TIME_GETCLOCK,&delay);
  369.    #else
  370.      delay=biostime(0,delay);
  371.    #endif
  372.    srand(delay % 32113);
  373.  
  374.  
  375.    if ( regs.h.al == 7 )
  376.      {
  377.       #if Microsoft
  378.         FP_SEG(ptr_screen) = MDA_SEG;
  379.         FP_OFF(ptr_screen) = 0x0000;
  380.      #else
  381.         ptr_screen = MK_FP(MDA_SEG,0);
  382.      #endif
  383.      }
  384.    else
  385.      {
  386.       #if Microsoft
  387.         FP_SEG(ptr_screen) = CGA_SEG;
  388.         FP_OFF(ptr_screen) = 0x0000;
  389.      #else
  390.         ptr_screen = MK_FP(CGA_SEG,0);
  391.      #endif
  392.      }
  393.  
  394.    cls();
  395.  
  396.    for ( i =  MIN_REG     ; i <= MAX_REG; i++ )
  397.       {
  398.        show_drawing(i,MIN_COL-1,COLOR_RAND,CHAR_FULL);
  399.        show_drawing(i,MAX_COL,COLOR_RAND,CHAR_FULL);
  400.       }
  401.    for ( i = (MIN_COL -1) ; i <= MAX_COL; i++ )
  402.        show_drawing(MAX_REG,i,COLOR_RAND,CHAR_FULL);
  403.    sprintf(mystring,                  " T _ T R I S   2.01m            %-20.20s     (c) 1989, RvW - EL     ",name);
  404.    show_string(0, 0,COLOR_LOGO,mystring);
  405.  
  406.    check_mouse();
  407.  
  408.    if ( mouse_present )
  409.      show_string(24,0,COLOR_LOGO," Mouse/Key : LEFT, DOWN, RIGHT, UP=pause   CLICK/RETURN=rotate   ESC=end        ");
  410.    else
  411.      show_string(24,0,COLOR_LOGO," Key : cursor LEFT, DOWN, RIGHT    UP=pause    RETURN=rotate    ESC=end         ");
  412.  
  413. }
  414.  
  415. /* ---------------------------------------------------------------------- */
  416. /* SHOW_SCORE                                                             */
  417. /* Show score and level                                                   */
  418. /*                                                                        */
  419. /* ---------------------------------------------------------------------- */
  420.  
  421. static void show_score()
  422. {
  423.    char        mystring[80];
  424.  
  425.    show_string(10,0,COLOR_SCORE,"             ");
  426.    sprintf(mystring," Level %1d / %1d ",start_level,level);
  427.    show_string(11,0,COLOR_SCORE,mystring);
  428.    show_string(12,0,COLOR_SCORE,"             ");
  429.    sprintf(mystring," Score %5ld ",points);
  430.    show_string(13,0,COLOR_SCORE,mystring);
  431.    show_string(14,0,COLOR_SCORE,"             ");
  432. }
  433.  
  434. /* ---------------------------------------------------------------------- */
  435. /* SHOW_TOPSCORE                                                          */
  436. /* Show one topscore by player                                            */
  437. /*                                                                        */
  438. /* ---------------------------------------------------------------------- */
  439.  
  440. static void show_topscore()
  441. {
  442.    int         i,
  443.                j;
  444.    char        mystring[80];
  445.    long        mystring_score,
  446.                mystring_gem,
  447.                mystring_gesp;
  448.    static   struct
  449.      {
  450.       int      number;
  451.       long     score[NUMBER_SCORE];
  452.       long     gem[NUMBER_SCORE];
  453.       long     gesp[NUMBER_SCORE];
  454.       char     name[NUMBER_SCORE][22];
  455.      }    score_record;
  456.    FILE       *score_filename;
  457.  
  458.    /* Read old scores */
  459.  
  460.    score_filename = fopen(SCORE_FILE,"rb");
  461.    if ( score_filename == NULL )
  462.       score_record.number = 0;
  463.    else
  464.      {
  465.       if ( fread(&score_record,sizeof(score_record),1,score_filename) < 1)
  466.          score_record.number = 0;
  467.       fclose(score_filename);
  468.      }
  469.  
  470.    /* Look for player in the list */
  471.  
  472.    name[21] = '\0';
  473.    strupr(name);
  474.    j  = 99;
  475.    for ( i = 0; i < score_record.number; i++ )
  476.       {
  477.        if ( strcmp(name,score_record.name[i]) == 0 )
  478.           j = i;
  479.       }
  480.    if ( j < 99 )
  481.       {
  482.       /* Compute score and average */
  483.  
  484.        if ( points > score_record.score[j] )
  485.           score_record.score[j] = points;
  486.        score_record.gem[j] = ( ( score_record.gem[j] * score_record.gesp[j] )
  487.                              + points ) / ( score_record.gesp[j] + 1);
  488.        score_record.gesp[j] = score_record.gesp[j] + 1;
  489.       }
  490.    else
  491.      {
  492.       if ( score_record.number < NUMBER_SCORE )
  493.         {
  494.          score_record.score[score_record.number] = points;
  495.          score_record.gem[score_record.number]   = points;
  496.          score_record.gesp[score_record.number]  = 1;
  497.          strcpy(score_record.name[score_record.number],name);
  498.          j = score_record.number;
  499.          score_record.number++;
  500.         }
  501.       else
  502.         {
  503.          if ( points > score_record.score[NUMBER_SCORE - 1] )
  504.           {
  505.           /* Remove last score and replace it my new score */
  506.  
  507.             score_record.score[NUMBER_SCORE - 1] = points;
  508.             score_record.gem[NUMBER_SCORE - 1]   = points;
  509.             score_record.gesp[NUMBER_SCORE - 1]  = 1;
  510.             strcpy(score_record.name[NUMBER_SCORE - 1],name);
  511.             j = NUMBER_SCORE - 1;
  512.           }
  513.         }
  514.      }
  515.  
  516.    if ( j < 99 )
  517.      {
  518.      while (   ( j > 0 ) &&  ( score_record.score[j] > score_record.score[j-1] ) )
  519.         {
  520.          strcpy(mystring,score_record.name[j-1]);
  521.          mystring_score = score_record.score[j-1];
  522.          mystring_gem   = score_record.gem[j-1];
  523.          mystring_gesp  = score_record.gesp[j-1];
  524.  
  525.          strcpy(score_record.name[j-1],score_record.name[j]);
  526.          score_record.score[j-1] = score_record.score[j];
  527.          score_record.gem[j-1]   = score_record.gem[j];
  528.          score_record.gesp[j-1]  = score_record.gesp[j];
  529.  
  530.          strcpy(score_record.name[j],mystring);
  531.          score_record.score[j] = mystring_score;
  532.          score_record.gem[j]   = mystring_gem;
  533.          score_record.gesp[j]  = mystring_gesp;
  534.  
  535.          j--;
  536.         }
  537.      }
  538.  
  539.    score_filename = fopen(SCORE_FILE,"wb");
  540.    if ( score_filename != NULL )
  541.      {
  542.       fwrite(&score_record,sizeof(score_record),1,score_filename);
  543.       fclose(score_filename);
  544.      }
  545.  
  546.    /* Show score list on the screen */
  547.  
  548.    for (i = 0; i < LOG_SIZE_REG; i++)
  549.       {
  550.        if ( i < score_record.number )
  551.         sprintf(mystring," Top %5ld, Avg. %5ld pnt. for %-16.16s ",
  552.                   score_record.score[i],
  553.                   score_record.gem[i],score_record.name[i]);
  554.        else
  555.           strcpy(mystring,"                                                 ");
  556.        show_string(MIN_REG+i,MIN_COL,COLOR_TOPSCORE,mystring);
  557.       }
  558. }
  559.  
  560. /* ---------------------------------------------------------------------- */
  561. /* LOG_DISPLAY                                                            */
  562. /*                                                                        */
  563. /* ---------------------------------------------------------------------- */
  564.  
  565. static void log_display()
  566. {
  567.    int         i,j;
  568.  
  569.    for ( i = 0; i < LOG_SIZE_REG; i++ )
  570.       {
  571.        for ( j = 0; j < LOG_SIZE_COL; j++ )
  572.         {
  573.          show_drawing(MIN_REG+i,MIN_COL+(j*2),log_screen[i][j],CHAR_FULL);
  574.          show_drawing(MIN_REG+i,MIN_COL+1+(j*2),log_screen[i][j],CHAR_FULL);
  575.         }
  576.       }
  577. }
  578.  
  579. /* ---------------------------------------------------------------------- */
  580. /* LOG_CLS                                                                */
  581. /*                                                                        */
  582. /* ---------------------------------------------------------------------- */
  583. static void log_cls()
  584. {
  585.    int         i,j;
  586.  
  587.    for ( i = 0 ; i < LOG_SIZE_REG; i++)
  588.       {
  589.        for ( j = 0; j < LOG_SIZE_COL; j++)
  590.            log_screen[i][j] = COLOR_BLACK;
  591.       }
  592.    log_display();
  593.    check_mouse();
  594. }
  595.  
  596. static void remove_full_line()
  597. {
  598.    int         i,
  599.                j;
  600.    int         x,
  601.                action;
  602.  
  603.    for ( i = LOG_SIZE_REG - 1 ; i > 0; i--)
  604.       {
  605.       /* Look for a gap on the line */
  606.  
  607.        action = 1;
  608.        for ( j = 0; j < LOG_SIZE_COL; j++)
  609.          {
  610.          if (log_screen[i][j] == COLOR_BLACK)
  611.             action = 0;
  612.          }
  613.        if ( action )
  614.         {
  615.           for ( x = i ; x > 0; x--)
  616.            {
  617.              for ( j = 0; j < LOG_SIZE_COL; j++)
  618.                  log_screen[x][j] = log_screen[x-1][j];
  619.              }
  620.           for ( j = 0; j < LOG_SIZE_COL; j++)
  621.               log_screen[0][j] = COLOR_BLACK;
  622.           beep();
  623.           i++;
  624.         }
  625.       }
  626.    log_display();
  627. }
  628.  
  629. /* ---------------------------------------------------------------------- */
  630. /* SHOW_FORM                                                              */
  631. /* Form manipulation                                                      */
  632. /* ---------------------------------------------------------------------- */
  633. static int show_form(action)
  634. int            action;                       /* 0 = init      */
  635.                                     /* 1 = down      */
  636.                                     /* 2 = right     */
  637.                                     /* 3 = left      */
  638.                                     /* 5 = rotate    */
  639. {
  640.    int         i,j;
  641.    static   int         reg,col;
  642.    int         mystring,change;
  643.  
  644.    change = 1;
  645.  
  646.    if ( action != 0 )
  647.      {
  648.      /* Blank old position */
  649.  
  650.       for ( i = 0; i < 3; i++ )
  651.         {
  652.          for ( j = 0; j < 3; j++ )
  653.           {
  654.             if ( huidige_form[i][j] != COLOR_BLACK )
  655.                log_screen[reg+i][col+j]   = COLOR_BLACK;
  656.           }
  657.         }
  658.      }
  659.  
  660.    switch(action)
  661.      {
  662.      case 0 :
  663.                reg = 0;
  664.                col = LOG_SIZE_COL / 2;
  665.                check_mouse();
  666.                break;
  667.      case 1 :
  668.                reg++;
  669.                break;
  670.      case 2 :
  671.                col++;
  672.                break;
  673.      case 3 :
  674.                col--;
  675.                break;
  676.      case 5 :
  677.                mystring = huidige_form[0][0];
  678.                huidige_form[0][0] = huidige_form[2][0];
  679.                huidige_form[2][0] = huidige_form[2][2];
  680.                huidige_form[2][2] = huidige_form[0][2];
  681.                huidige_form[0][2] = mystring;
  682.                mystring = huidige_form[0][1];
  683.                huidige_form[0][1] = huidige_form[1][0];
  684.                huidige_form[1][0] = huidige_form[2][1];
  685.                huidige_form[2][1] = huidige_form[1][2];
  686.                huidige_form[1][2] = mystring;
  687.                break;
  688.      }
  689.  
  690.    for ( i = 0; i < 3; i++ )
  691.      {
  692.       for ( j = 0; j < 3; j++ )
  693.         {
  694.          if ( huidige_form[i][j] != COLOR_BLACK )
  695.           {
  696.             if  ( log_screen[reg+i][col+j] != COLOR_BLACK )
  697.                 change = 0;
  698.           if ( ( reg+i ) >= LOG_SIZE_REG )
  699.              change = 0;
  700.           if ( ( reg+i ) < 0 )
  701.              change = 0;
  702.           if ( ( col+j ) >= LOG_SIZE_COL )
  703.              change = 0;
  704.           if ( ( col+j ) < 0 )
  705.              change = 0;
  706.           }
  707.         }
  708.      }
  709.  
  710.    if ( !change )
  711.      {
  712.       switch(action)
  713.         {
  714.         case 1 :
  715.                   reg--;
  716.                   break;
  717.         case 2 :
  718.                   col--;
  719.                   break;
  720.         case 3 :
  721.                   col++;
  722.                   break;
  723.         case 5 :
  724.                   mystring = huidige_form[0][0];
  725.                   huidige_form[0][0] = huidige_form[0][2];
  726.                   huidige_form[0][2] = huidige_form[2][2];
  727.                   huidige_form[2][2] = huidige_form[2][0];
  728.                   huidige_form[2][0] = mystring;
  729.                   mystring = huidige_form[0][1];
  730.                   huidige_form[0][1] = huidige_form[1][2];
  731.                   huidige_form[1][2] = huidige_form[2][1];
  732.                   huidige_form[2][1] = huidige_form[1][0];
  733.                   huidige_form[1][0] = mystring;
  734.                   break;
  735.         }
  736.      }
  737.  
  738.    /* form at new position */
  739.  
  740.    for ( i = 0; i < 3; i++ )
  741.      {
  742.       for ( j = 0; j < 3; j++ )
  743.         {
  744.          if ( huidige_form[i][j] != COLOR_BLACK )
  745.             log_screen[reg+i][col+j]   = huidige_form[i][j];
  746.         }
  747.      }
  748.  
  749.    log_display();
  750.  
  751.    return(change);
  752. }
  753.  
  754. /* ---------------------------------------------------------------------- */
  755. /* INIT_FORMS                                                            */
  756. /*                                                                        */
  757. /* ---------------------------------------------------------------------- */
  758. static void init_forms()
  759. {
  760.    int         i,
  761.                j;
  762.    int         color;
  763.  
  764.    form_point[0]  = 10;
  765.    color          = COLOR_BROWN;
  766.    forms[0][0][0] = COLOR_BLACK;     /*   ..#      */
  767.    forms[0][0][1] = COLOR_BLACK;     /*   .##      */
  768.    forms[0][0][2] = color;           /*   .#.      */
  769.  
  770.    forms[0][1][0] = COLOR_BLACK;
  771.    forms[0][1][1] = color;
  772.    forms[0][1][2] = color;
  773.  
  774.    forms[0][2][0] = COLOR_BLACK;
  775.    forms[0][2][1] = color;
  776.    forms[0][2][2] = COLOR_BLACK;
  777.  
  778.    form_point[1]  = 10;
  779.    color          = COLOR_BLUE;
  780.    forms[1][0][0] = color ;          /*   #..      */
  781.    forms[1][0][1] = COLOR_BLACK;     /*   ##.      */
  782.    forms[1][0][2] = COLOR_BLACK;     /*   .#.      */
  783.  
  784.    forms[1][1][0] = color ;
  785.    forms[1][1][1] = color ;
  786.    forms[1][1][2] = COLOR_BLACK;
  787.  
  788.    forms[1][2][0] = COLOR_BLACK;
  789.    forms[1][2][1] = color ;
  790.    forms[1][2][2] = COLOR_BLACK;
  791.  
  792.    form_point[2]  = 1;
  793.    color          = COLOR_RED;
  794.    forms[2][0][0] = COLOR_BLACK;     /*   ...      */
  795.    forms[2][0][1] = COLOR_BLACK;     /*   ###      */
  796.    forms[2][0][2] = COLOR_BLACK;     /*   ...      */
  797.  
  798.    forms[2][1][0] = color ;
  799.    forms[2][1][1] = color ;
  800.    forms[2][1][2] = color ;
  801.  
  802.    forms[2][2][0] = COLOR_BLACK;
  803.    forms[2][2][1] = COLOR_BLACK;
  804.    forms[2][2][2] = COLOR_BLACK;
  805.  
  806.    form_point[3]  = 7;
  807.    color          = COLOR_VIOLET;
  808.    forms[3][0][0] = COLOR_BLACK;     /*   ...      */
  809.    forms[3][0][1] = COLOR_BLACK;     /*   ###      */
  810.    forms[3][0][2] = COLOR_BLACK;     /*   ..#      */
  811.  
  812.    forms[3][1][0] = color ;
  813.    forms[3][1][1] = color ;
  814.    forms[3][1][2] = color ;
  815.  
  816.    forms[3][2][0] = COLOR_BLACK;
  817.    forms[3][2][1] = COLOR_BLACK;
  818.    forms[3][2][2] = color ;
  819.  
  820.    form_point[4]  = 7;
  821.    color          = COLOR_YELLOW;
  822.    forms[4][0][0] = COLOR_BLACK;     /*   ...      */
  823.    forms[4][0][1] = COLOR_BLACK;     /*   ###      */
  824.    forms[4][0][2] = COLOR_BLACK;     /*   #..      */
  825.  
  826.    forms[4][1][0] = color ;
  827.    forms[4][1][1] = color ;
  828.    forms[4][1][2] = color ;
  829.  
  830.    forms[4][2][0] = color ;
  831.    forms[4][2][1] = COLOR_BLACK;
  832.    forms[4][2][2] = COLOR_BLACK;
  833.  
  834.    form_point[5]  = 4;
  835.    color          = COLOR_GREY;
  836.    forms[5][0][0] = COLOR_BLACK;     /*   ...      */
  837.    forms[5][0][1] = COLOR_BLACK;     /*   ##.      */
  838.    forms[5][0][2] = COLOR_BLACK;     /*   ##.      */
  839.  
  840.    forms[5][1][0] = color ;
  841.    forms[5][1][1] = color ;
  842.    forms[5][1][2] = COLOR_BLACK;
  843.  
  844.    forms[5][2][0] = color ;
  845.    forms[5][2][1] = color ;
  846.    forms[5][2][2] = COLOR_BLACK;
  847.  
  848.    form_point[6]  = 3;
  849.    color          = COLOR_GREEN;
  850.    forms[6][0][0] = COLOR_BLACK;     /*   ...      */
  851.    forms[6][0][1] = COLOR_BLACK;     /*   .#.      */
  852.    forms[6][0][2] = COLOR_BLACK;     /*   ###      */
  853.  
  854.    forms[6][1][0] = COLOR_BLACK;
  855.    forms[6][1][1] = color ;
  856.    forms[6][1][2] = COLOR_BLACK;
  857.  
  858.    forms[6][2][0] = color ;
  859.    forms[6][2][1] = color ;
  860.    forms[6][2][2] = color;
  861.  
  862. }
  863.  
  864. /* ---------------------------------------------------------------------- */
  865. /* CHOOSE_FORM                                                            */
  866. /* Random choose of the form                                              */
  867. /*                                                                        */
  868. /* ---------------------------------------------------------------------- */
  869.  
  870. static void choose_form()
  871. {
  872.    int         i,j,x;
  873.    static   int         tel = 0;
  874.    static   long        vpunten = 0;
  875.  
  876.    if ( vpunten > points )
  877.      {
  878.       vpunten = 0;
  879.       tel = 0;
  880.      }
  881.  
  882.    x = rand() % NUMBER_FORMS;
  883.  
  884.    for ( i = 0; i < 3 ; i++)
  885.      {
  886.       for ( j = 0; j < 3; j++ )
  887.           huidige_form[i][j] = forms[x][i][j];
  888.      }
  889.    points += form_point[x] + start_level;
  890.  
  891.    tel++;
  892.  
  893.    if (  ( ( tel % 25 ) == 0 ) && ( level < 9 ) )
  894.      {
  895.       level++;
  896.       beep();
  897.      }
  898.  
  899.    show_score();
  900.  
  901.    vpunten = points;
  902.    REACTION_TIME = 10 - level;
  903. }
  904.  
  905. /* ------------------------------------------------------------------------ */
  906. /*                                                                          */
  907. /*           MAIN                                                           */
  908. /*                                                                          */
  909. /* ------------------------------------------------------------------------ */
  910.  
  911. void main()
  912. {
  913.    int         i;
  914.    char strlevel[3];
  915.  
  916.    key = 0;
  917.  
  918.    while ( key != KEY_END )
  919.      {
  920.  
  921.       level  = 99;
  922.  
  923.       strcpy(name,"");
  924.       while ( name[0] == '\0' )
  925.         {
  926.          clrscr();
  927.         printf("\nWhat is your name > ");
  928.          gets(name);
  929.         }
  930.      while (  ( level < 0 ) || ( level > 9 ) )
  931.         {
  932.         printf("\nDear %s, choose your level ( 0..9) > ",name);
  933.         gets(strlevel);
  934.         level=atoi(strlevel);
  935.         }
  936.      cursor(0,26);
  937.       start_level = level;
  938.       points = 0;
  939.       init_screen();
  940.       log_cls();
  941.       init_forms();
  942.       choose_form();
  943.  
  944.       key = 0;
  945.  
  946.      while (  ( key != KEY_END ) && ( show_form(0) ) )
  947.       {
  948.         while (  ( key != KEY_END ) && ( show_form(1) ) )
  949.           {
  950.              action();
  951.  
  952.            while (   ( !action() ) &&  ( key != KEY_END ) )
  953.              {
  954.                 if ( read_key() )
  955.                 {
  956.                    switch(key)
  957.                    {
  958.                       case KEY_RIGHT    :
  959.                                           show_form(2);
  960.                                           break;
  961.                       case KEY_LEFT     :
  962.                                           show_form(3);
  963.                                           break;
  964.                       case KEY_DROP     :
  965.                                           i = 0;
  966.                                           while( show_form(1)) i++;
  967.                                           points = points + start_level +
  968.                                              ((i / LOG_SIZE_REG) * start_level);
  969.                                           break;
  970.                       case KEY_PAUSE    :
  971.                                           wait_key();
  972.                                           break;
  973.                       case KEY_ROTATE   :
  974.                                           show_form(5);
  975.                                           break;
  976.                    }
  977.                 }
  978.              }
  979.          }
  980.          remove_full_line();
  981.          flush_key_buffer();
  982.          choose_form();
  983.       }
  984.  
  985.       if ( key != KEY_END )
  986.       {
  987.          show_topscore();
  988.          flush_key_buffer();
  989.         wait_key();
  990.       }
  991.  
  992.       cls();
  993.    }
  994. }
  995.